package com.wkw.jkyf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wkw.jkyf.common.ResultMapUtil;
import com.wkw.jkyf.pojo.Returngoods;


import com.wkw.jkyf.service.IReturngoodsService;


import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Date;

@Controller
@RequestMapping(value = "/returngoods")
public class ReturngoodsController {
    @Resource
    private IReturngoodsService returngoodsService;

    @RequestMapping
    public String login(){
        return "/returngoods";
    }

    /*
    分页查询供应商列表
     */
    @RequestMapping("/returngoodsQueryPage")
    @ResponseBody
    public Object supplierQueryPage(String param, @RequestParam(defaultValue = "1")int page, @RequestParam(defaultValue = "10")int pageSize){
        try{
            IPage<Returngoods> iPage = returngoodsService.selectReturngoodsPage(page,pageSize,param);
            return ResultMapUtil.getHashMapMysqlPage(iPage);
        }catch (Exception e){
            return ResultMapUtil.getHashException(e);
        }

    }
    //跳转到添加页面
    @RequestMapping(value = "/returngoodsPage")
    public String supplierPage(){
        return "/returngoodsPage";
    }

    //添加
    @RequestMapping(value = "/returngoodsAdd")
    @ResponseBody
    public Object returngoodsAdd(Returngoods returngoods){
        try {
            //    returngoods.setOperatetime(new Date());
            int i = returngoodsService.addReturngoods(returngoods);
            return ResultMapUtil.getHashMapSave(i);
        } catch (Exception e) {
            return ResultMapUtil.getHashException(e);
        }

    }

    //按id查询
    @RequestMapping(value = "/returngoodsQueryById")
    public String returngoodsQueryById(@RequestParam(name = "id",required = true)Integer id, Model model) {
        Returngoods returngoods= returngoodsService.queryReturngoodsById(id);
        model.addAttribute("obj",returngoods);
        return "/returngoodsPage";
    }

    //修改一个供应商
    @RequestMapping(value = "/returngoodsEdit")
    @ResponseBody
    public Object returngoodsEdit(Returngoods returngoods) {
        try {
            int i= returngoodsService.editReturngoods(returngoods);
            return ResultMapUtil.getHashMapSave(i);
        } catch (Exception e) {
            return  ResultMapUtil.getHashException(e);
        }
    }

    // 删除一个供应商
    @RequestMapping(value = "/returngoodsDelById")
    @ResponseBody
    public Object returngoodsDelById(Integer id) {
        try {
            int i= returngoodsService.deleteReturngoodsById(id);
            return ResultMapUtil.getHashMapDel(i);
        } catch (Exception e) {
            return  ResultMapUtil.getHashException(e);
        }
    }

}
